package com.yf_health.yidun;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.hardware.Camera;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.StrictMode;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.App;
import com.SoftKey.ASyunew699;
import com.arcsoft.facedetection.AFD_FSDKEngine;
import com.arcsoft.facedetection.AFD_FSDKError;
import com.arcsoft.facedetection.AFD_FSDKFace;
import com.diankang.dialog.UpdateingDialog;
import com.diankang.updateversion.ApkUtils;
import com.diankang.updateversion.HttpRequest;
import com.diankang.updateversion.SDCardUtils;
import com.diankang.updateversion.ServerReqAddress;
import com.diankang.updateversion.UpdateVersionUtil;
import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.SyncHttpClient;
import com.loopj.android.http.TextHttpResponseHandler;
import com.serenegiant.vo.utils.Catch;
import com.serenegiant.vo.utils.MResource;
import com.yf_health.yidun.util.QRCodeUtil;
import com.yf_health.yidun.util.UsbPermissionCallback;
import com.yf_health.yidun.util.UsbPermissionUtil;
import com.yf_health.yidun.wifi.WifiSelecterActivity;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import cz.msebera.android.httpclient.Header;

import static android.content.ContentValues.TAG;
import static com.yf_health.yidun.YFResultActivity.readInputStream;


/**
 * 检测主界面
 * @Description
 * @Author AntLiu
 * @Update 2018/10/17 1:43
 */
@SuppressLint({"NewApi"})
public class YFMainActivity extends Activity implements SurfaceHolder.Callback {

    public static final boolean DEVELOPER_MODE = false;

    /**
     * 接口URL：验证加密狗
     */
    private static final String URL_FINAL = "http://www.zyfrontendserver.healthpool1276.com/health/pad3.0/pc.receivepass.php";
    /**
     * 接口URL：
     * TODO 接口内容
     */
    private static final String URL_START = "http://www.zyfrontendserver.healthpool1276.com/health/pad3.0/pc.receivekey.php";
    /**
     * 接口URL：上传device 获取二维码
     */
    private static final String URL_ENCODE = "http://www.zyfrontendserver.healthpool1276.com/health/pad3.0/pc.qrcode.php";
    /**
     * 接口URL：获取用户BMI信息
     */
    private static final String URL_USER = "http://www.zyfrontendserver.healthpool1276.com/health/pad3.0/pc.getdevice.php";

    /**
     * 虹软面部识别引擎
     */
    static AFD_FSDKEngine afdFsdkEngine = new AFD_FSDKEngine();

    /**
     * 设备编号（原：Device）
     */
    private String deviceId;//TODO CHECK : VALUE CHANGED (AS DEVICE_ID+YYYYMMDDHHMMSS), AND CAUSED 2ND-TIME ERROR

//    private String deviceIdEncode;

    private String deviceId2;//DeviceOld

    /**
     * USB加密狗设备（原：DevicePath）
     */
    private UsbDevice usbEncryptionDogDevice;

    /**
     * （原：yt_j6）
     */
    ASyunew699 aSyunew699;

    /**
     * 狗数（和加密狗相关）
     * TODO CHECK
     */
    private String goushu;

    /**
     * 后八位（和加密狗相关）
     */
    private String houbawei;

    /**
     * （原：birtime）
     */
    private double birthTime;
    /**
     * （原：brM）
     */
    private String birthMonth;
    /**
     * （原：brY）
     */
    private String birthYear;

    /**
     * 升级弹窗界面
     */
    private UpdateingDialog updatingDialog;
    private UpdateingDialog.Builder updatingDialogBuilder;

    /**
     * 摄像头
     */
    private Camera camera;


    /**
     * 网络请求客户端-获取用户信息（原：clientuser）
     */
    private AsyncHttpClient httpClientUser;

    /**
     * 倒计时
     */
    private int djs;

    /**
     * 新版本文件
     */
    private File updateFile;

    /**
     * 数据接口访问返回值，json格式的对象
     * TODO 有多个接口都使用了该jsonObject，建议拆开分别建立对象。
     */
    private JSONObject jsonObject2;

    private String random;
    private TextView daojishi;
    private ImageView deviceimg;
    private ImageView imgview;
    private TextView devicetext;
    private String showTwoTim;
    private SurfaceHolder surfaceholder;
    private SurfaceView surfaceview;
    /**
     * （原：tishiyu）
     */
    private TextView noticeTextView1;
    /**
     * （原：tishiyu1）
     */
    private TextView noticeTextView2;
    private WebView webview;
    private String weight;
    private TextView versionView;
    private TextView dianchiTv;
    private ImageView wifi_iconImg;

    //进程类变量（共计15个runnable）
    Handler handlerclose;
    Handler handlerdaojishi;
    Handler handlerencode1;
    Handler handlerfailGou;
    Handler handlerfinalGou1;
    Handler handlerstartGou;
    Handler handlerstartGou1;
    Handler handlerstartcl;
    Handler handlersuanfaload;
    Handler handlerupdateing;
    Handler handleruser;
    Handler handlerversion;
    Handler handlerxianshi;

    /**
     * 线程-加密狗-验证加密狗
     * URL: YFMainActivity.this.URL_FINAL
     */
    Runnable networkTaskGou;
    /**
     * 线程-加密狗-获取随机码
     */
    Runnable networkTaskStartGou;
    /**
     * 线程-界面-结束当前界面
     */
    Runnable runnableclose;
    /**
     * 线程-界面-显示倒计时（并按秒更新）
     */
    Runnable runnabledaojishi;
    /**
     * 线程-上传deviceId获取微信二维码
     */
    Runnable runnableencode1;
    /**
     * 线程-加密狗-提示联网失败（networkTaskStartGou获取随机码失败后调用）
     */
    Runnable runnablefailGou;
    /**
     * 线程-（runnablesuanfaload之后，启动networkTaskGou）
     */
    Runnable runnablefinalGou1;
    /**
     * 线程-获取ID_1、ID_2，（找到加密锁√之后的回调，之后会启动runnablestartGou1）
     * f_getid()
     */
    Runnable runnablestartGou;
    /**
     * 线程-启动networkTaskStartGou（线程-加密狗-获取随机码）
     */
    Runnable runnablestartGou1;
    /**
     * 线程-引导用户开始测量（每秒循环直至Catch.camera2start==true）
     * 调用：
     *   runnableencode1（线程-上传deviceId获取微信二维码）
     *   runnabledaojishi（线程-界面-显示倒计时）
     */
    Runnable runnablestartcl;
    /**
     * 线程-（networkTaskStartGou获取随机码成功后调用）
     * 调用：
     *  f_EncString();计算goushu
     *  f_YReadString();计算houbawei
     *  runnablefinalGou1
     */
    Runnable runnablesuanfaload;
    /**
     * 线程-更新-下载更新文件（runnableversion成功后调用）
     * URL: ServerReqAddress.URL_UPDATE_MAX_VERSION_FILE
     */
    Runnable runnableupdateing;
    /**
     * 获取用户在微信填写的BMI信息（循环调用，直至成功）
     * 入口：runnableencode1（上传deviceId获取微信二维码）
     * URL: YFMainActivity.this.URL_USER
     */
    Runnable runnableuser;
    /**
     * 线程-更新-获取最新版本，判断是否升级
     * URL:ServerReqAddress.URL_UPDATE_MAX_VERSION
     * 调用：
     *   runnableupdateing（线程-更新-下载更新文件）
     */
    Runnable runnableversion;
    /**
     * 显示设备二维码（左下）
     * 入口： networkTaskGou（线程-加密狗-验证加密狗）
     */
    Runnable runnablexianshi;
    ASyunew699 yt_j6;
    private static final int REQUEST_EXTERNAL_STORAGE = 1;
    private static String[] PERMISSIONS_STORAGE = {
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.CAMERA,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            "android.permission.PERMISSION_GRANTED",};

    static {
        System.loadLibrary("mm");
    }
    private Camera.Size previewSize;
    public HttpUtils httpUtils;
    private boolean hasFace;
        public YFMainActivity() {
//            Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"YFMainActivity().start");
            this.camera = null;
            this.deviceId = "";
            this.djs = 60;
            this.random = "";
            this.showTwoTim = "";
            initRunnables();
//            Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"YFMainActivity().end");
        }

        private void initRunnables(){
        this.deviceId2 = "";
        this.handlerversion = new Handler();
        this.runnableversion = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnableversion.start");
//                Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "runnableversion Start");
                HttpRequest.get(ServerReqAddress.URL_UPDATE_MAX_VERSION, (HttpRequest.RequestCallBackListener) new HttpRequest.RequestCallBackListener() {
                    @Override
                    public void onFailure(final String s) {
//                        Toast.makeText((Context) YFMainActivity.this,  "连接超时", Toast.LENGTH_SHORT);
//                        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "runnableversion.ajax.onFailure:"+s);
                    }

                    @Override
                    public void onSuccess(final String s) {
//                        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "runnableversion.ajax.onSuccess:"+ s);
                        final int versionCode = ApkUtils.getVersionCode((Context) YFMainActivity.this);
                        final int int1 = Integer.parseInt(s);
//                        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "maxVersion="+ String.valueOf(int1) + ",currentVersion=" + versionCode);
                        if (int1 > versionCode) {
                            UpdateVersionUtil.showDialog((Context) YFMainActivity.this, UpdateVersionUtil.localCheckedVersion((Context) YFMainActivity.this));
                            YFMainActivity.this.handlerupdateing.postDelayed(YFMainActivity.this.runnableupdateing, 500L);
                        }
//                        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "runnableversion.ajax.onSuccess,End:"+ int1+">?<"+versionCode);
                    }
                });
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnableversion.end");
            }
        };
        this.handlerupdateing = new Handler();
        this.runnableupdateing = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnableupdateing.start");
                if (Catch.update) {
                    YFMainActivity.this.handlerupdateing.removeCallbacks(YFMainActivity.this.runnableupdateing);
                    YFMainActivity.this.downLoadFile();
                    return;
                }
                YFMainActivity.this.handlerupdateing.postDelayed(YFMainActivity.this.runnableupdateing, 500L);
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnableupdateing.end");
            }
        };
        this.handlerstartcl = new Handler();
        this.runnablestartcl = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablestartcl.start");
//                Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnablestartcl Start."+new Date().toString());
                YFMainActivity.this.djs = 60;
                YFMainActivity.this.noticeTextView1.setText("脸部对准摄像头");
                YFMainActivity.this.noticeTextView2.setText( "生成您的监测二维码");
                Catch.reset = true;
                YFMainActivity.this.imgview.setVisibility(View.GONE);
//                Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "Catch.camera2start="+Catch.camera2start);
                if (Catch.camera2start) {//TODO CHECK LOGIC
                    Catch.reset = false;
                    Catch.camera2start = false;
                    Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/,"进入流程");
                    YFMainActivity.this.deleteFile1("face.jpg");
                    YFMainActivity.this.handlerencode1.postDelayed(YFMainActivity.this.runnableencode1, 100L);
                    YFMainActivity.this.noticeTextView1.setText("请使用微信或芸享APP扫码");
                    YFMainActivity.this.noticeTextView2.setText("开启您的健康之旅");
                    YFMainActivity.this.daojishi.setVisibility(View.VISIBLE);
                    YFMainActivity.this.handlerdaojishi.post(YFMainActivity.this.runnabledaojishi);
                    YFMainActivity.this.handlerstartcl.removeCallbacks(YFMainActivity.this.runnablestartcl);
//                    return;
                }else{
                    YFMainActivity.this.handlerstartcl.postDelayed(YFMainActivity.this.runnablestartcl, 1000L);
                }
//                Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnablestartcl End."+new Date().toString());
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablestartcl.end");
            }
        };
        this.handlerencode1 = new Handler();
        this.runnableencode1 = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnableencode1.start");
//                Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnableencode1 Start."+new Date().toString());
                final AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
                final RequestParams requestParams = new RequestParams();
                YFMainActivity.this.imgview.setVisibility(View.VISIBLE);
                requestParams.setUseJsonStreamer(true);
                requestParams.put("Device", YFMainActivity.this.deviceId);
//                Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "上传device 获取二维码,deviceId="+YFMainActivity.this.deviceId);
//                Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnableencode1 POST to pc.qrcode.php."+new Date().toString());
                asyncHttpClient.post(YFMainActivity.this.URL_ENCODE, requestParams, new AsyncHttpResponseHandler() {
                    @Override

                    public void onFailure(final int n, final Header[] array, final byte[] array2, final Throwable t) {
                        YFMainActivity.this.handlerencode1.postDelayed(YFMainActivity.this.runnableencode1, 1000L);
//                        Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnableencode1 POST to pc.qrcode.php FAILURE."+new Date().toString());
                    }

                    @Override
                    public void onSuccess(final int n, final Header[] array, final byte[] array2) {
                        Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnableencode1 POST to pc.qrcode.php SUCCESS Start."+new Date().toString());
//                            YFMainActivity.this.handlerencode1.postDelayed(YFMainActivity.this.runnableencode1, 1000L);
                        try {
                            final String s = new String(array2, "utf-8");
                            Log.w("[E]"+"AsyncHttp", new StringBuilder(String.valueOf(s)).toString());
                            YFMainActivity.this.jsonObject2 = new JSONObject(s);
//                                if(YFMainActivity.this.jsonObject2.getBoolean("success")==false){
//                                    YFMainActivity.this.handlerencode1.postDelayed(YFMainActivity.this.runnableencode1, 1000L);
//                                    return;
//                                }
                            final String string = YFMainActivity.this.jsonObject2.getString("codeUrl");
                            //TODO GUESS : 2ND-TIME
                            YFMainActivity.this.deviceId = YFMainActivity.this.jsonObject2.getString("Device");
//                            YFMainActivity.this.deviceIdEncode = YFMainActivity.this.jsonObject2.getString("Device");

                            YFMainActivity.this.webview.setVisibility(View.VISIBLE);
                            final WebSettings settings = YFMainActivity.this.webview.getSettings();
                            settings.setUseWideViewPort(true);
                            settings.setLoadWithOverviewMode(true);
                            settings.setSupportZoom(true);
                            settings.setBuiltInZoomControls(true);
                            settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
                            settings.setAllowFileAccess(true);
                            settings.setSupportMultipleWindows(true);
                            settings.setDomStorageEnabled(true);
                            settings.setJavaScriptEnabled(false);
                            YFMainActivity.this.webview.loadUrl(string);
                            YFMainActivity.this.webview.setWebViewClient((WebViewClient) new WebViewClient() {
                                public boolean shouldOverrideUrlLoading(final WebView webView, final String s) {
                                    webView.loadUrl(s);
                                    return true;
                                }
                            });
                            YFMainActivity.this.handleruser.postDelayed(YFMainActivity.this.runnableuser, 100L);
//                            Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnableencode1 POST to pc.qrcode.php SUCCESS End."+new Date().toString());
                        } catch (JSONException ex) {
                            ex.printStackTrace();
                        } catch (UnsupportedEncodingException ex2) {
                            ex2.printStackTrace();
                        }
                    }
                });
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnableencode1.end");
            }
        };
        //this.djs = 60;

        this.handlerdaojishi = new Handler();
        this.runnabledaojishi = new Runnable() {
            @SuppressLint({"NewApi"})
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnabledaojishi.start");
//                Log.v(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnabledaojishi Start."+new Date().toString());
                if (YFMainActivity.this.djs == 0) {
                    YFMainActivity.this.deviceId = YFMainActivity.this.deviceId2;
                    YFMainActivity.this.daojishi.setVisibility(View.GONE);
                    YFMainActivity.this.webview.setVisibility(View.GONE);
                    YFMainActivity.this.handlerstartcl.postDelayed(YFMainActivity.this.runnablestartcl, 100L);
                    YFMainActivity.this.handleruser.removeCallbacks(YFMainActivity.this.runnableuser);
//                    YFMainActivity.this.httpClientUser.cancelAllRequests(true);
                    YFMainActivity.this.daojishi.setBackground((Drawable) null);
                    if (YFMainActivity.this.httpClientUser != null) {
                        YFMainActivity.this.httpClientUser.cancelAllRequests(true);
                    }
                } else {
                    YFMainActivity.this.daojishi.setText(("倒计时：" + YFMainActivity.this.djs + "秒"));
                    YFMainActivity.this.handlerdaojishi.postDelayed(YFMainActivity.this.runnabledaojishi, 1000L);
                    YFMainActivity.this.djs -= 1;
                }
//                Log.v(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnabledaojishi Start."+new Date().toString());
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnabledaojishi.end");
            }
        };
        this.handleruser = new Handler();


        /**
         * @Description runnableuser反编（简略版）Copy & Edit From YfAppActivity.runnableuser
         * @Author AntLiu
         * @Update 2018/10/28 12:08
         */
        this.runnableuser = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnableuser.start");
//                Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnableuser Start."+new Date().toString());
                //YFMainActivity.this.deviceId
//                Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "YFMainActivity.this.deviceId="+YFMainActivity.this.deviceId);
                YFMainActivity.this.httpClientUser = new AsyncHttpClient();
                RequestParams requestParams = new RequestParams();
                requestParams.setUseJsonStreamer(true);
                requestParams.put("Device", YFMainActivity.this.deviceId);
                if (YFMainActivity.this.httpClientUser != null) {
                    YFMainActivity.this.httpClientUser.cancelAllRequests(true);
                    YFMainActivity.this.httpClientUser.cancelAllRequests(true);
                    YFMainActivity.this.httpClientUser.cancelAllRequests(true);
                }
//                Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnableuser POST to URL_USER(pc.getdevice.php)."+new Date().toString());
//                Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "runnableuser.http.requestParams.Device=" + YFMainActivity.this.deviceId);
                Gson gson = new Gson();
                String json = gson.toJson(requestParams);
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Networks:"+"URL_USER.beforeSend:"+json.toString());
                YFMainActivity.this.httpClientUser.post(YFMainActivity.this.URL_USER, requestParams, new AsyncHttpResponseHandler() {
                    @Override
                    public void onFailure(final int n, final Header[] array, final byte[] responseBody, final Throwable t) {
//                        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnableuser POST to URL_USER(pc.getdevice.php) FAILURE."+new Date().toString());
                        try {
                            String responseBodyStr = "";
                            if(responseBody!=null) {
                                responseBodyStr = new String(responseBody, "utf-8").trim();
                            }
//                            Log.e(YFMainActivity.this.getClass().getSimpleName(), "Networks:" + "URL_USER.Error:" + responseBodyStr);
                            YFMainActivity.this.handleruser.postDelayed(YFMainActivity.this.runnableuser, 1000L);
                        }catch (UnsupportedEncodingException ex){
                            ex.printStackTrace();
                        }
                    }

                    @Override
                    public void onSuccess(final int statusCode, final Header[] headers, final byte[] responseBody) {
//                        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnableuser POST to URL_USER(pc.getdevice.php) SUCCESS Start."+new Date().toString());
                        try {
                            String responseBodyStr = new String(responseBody, "utf-8");
//                            Log.e(YFMainActivity.this.getClass().getSimpleName(), "Networks:" + "URL_USER.Success:" + responseBodyStr);
                            StringBuilder sb = new StringBuilder(responseBodyStr);

                            YFMainActivity.this.jsonObject2 = new JSONObject(responseBodyStr);

                            String success = YFMainActivity.this.jsonObject2.getString("success");//59~61
                            if("true".equals(success)){
//                                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Networks:" + "URL_USER.Success.Success:" + responseBodyStr);
                                Log.w("[E]"+"DSDADSADSADAD", responseBodyStr);
                                String sex = YFMainActivity.this.jsonObject2.getString("sex");//153~168
                                String age = YFMainActivity.this.jsonObject2.getString("age");//169~184
                                String height = YFMainActivity.this.jsonObject2.getString("height");//185~200
                                String weight = YFMainActivity.this.jsonObject2.getString("weight");//201~216
                                String name = YFMainActivity.this.jsonObject2.getString("name");//218~233
                                YFMainActivity.this.webview.setVisibility(View.GONE);//234~246
                                YFMainActivity.this.handleruser.removeCallbacks(YFMainActivity.this.runnableuser);//249~269
//                                YFMainActivity.this.height = height;
                                YFMainActivity.this.weight = weight;
                                String[] brs = "1990-07-10".split("-");//TODO CHECK WHY : WHY NOT json.getDateStr ,Guess They're Error Codes(OR 1970-01-01 ?)
                                YFMainActivity.this.birthYear = brs[0];//316~332
                                YFMainActivity.this.birthMonth = brs[1];//335~351
                                String ymd = YFMainActivity.this.birthYear + "-" + YFMainActivity.this.birthMonth + "-" + brs[2];
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                                Date date = sdf.parse(ymd);//astore_2
                                Double birtime = (date.getTime()/1000L+28800L)/24L/3600L+25569D;//TODO confirm if right: Convert Java Date To Windows Date => +25569D
                                YFMainActivity.this.birthTime = birtime;

//                                StringBuilder sb3 = new StringBuilder(YFMainActivity.this.height);//464~486
                                StringBuilder sb3 = new StringBuilder();
                                sb3.append(height);
                                sb3.append(";");
                                sb3.append(YFMainActivity.this.weight);//489~499
                                sb3.append(";");
                                sb3.append(YFMainActivity.this.birthTime);//507~517
                                sb3.append(";");
                                sb3.append(YFMainActivity.this.birthYear);//525~540
                                sb3.append(";");
                                sb3.append(YFMainActivity.this.birthMonth);//543~558
                                sb3.append(";");
                                sb3.append(YFMainActivity.this.deviceId);//561~571//TODO CHECK , DIFFERENT FROM YfAppActivity : YFMainActivity.this.deviceId

                                Catch.xinxi = sb3.toString();//574~577
//                                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Values:" + "Catch.xinxi:" + Catch.xinxi);

                                File storageDirectory = Environment.getExternalStorageDirectory();
                                File dataDirectory  = new File(storageDirectory.getPath()+"/ResultData/");
                                YFMainActivity.this.deleteAllFiles(dataDirectory);//612~620
                                if(YFMainActivity.this.camera == null){//661
                                    YFMainActivity.this.finish();
//                                    return;
                                }else{
//                                    Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "camera.setPreviewCallback(null)");
                                    YFMainActivity.this.camera.setPreviewCallback(null);//664~675
                                    YFMainActivity.this.camera.stopPreview();
                                    YFMainActivity.this.camera.release();
                                }
                                //TODO CHECK: : MOVED FROM 416 IF("false".equals(success))
                                YFMainActivity.this.handleruser.removeCallbacks(YFMainActivity.this.runnableuser);//74~94
//                                Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnableuser POST to URL_USER(pc.getdevice.php) SUCCESS Ending."+new Date().toString());
                                Intent intent = new Intent(YFMainActivity.this, YFResultActivity.class);
                                YFMainActivity.this.startActivity(intent);
                                YFMainActivity.this.finish();
                            }else{
                                YFMainActivity.this.handleruser.postDelayed(YFMainActivity.this.runnableuser, 1000L);//97~123
                            }
                        }catch (JSONException ex){
                            ex.printStackTrace();
                            return;
                        }catch (UnsupportedEncodingException ex){
                            ex.printStackTrace();
                            return;
                        }catch (ParseException ex){
                            ex.printStackTrace();
                            return;
                        }
                    }
                });
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnableuser.end");
            }
        };



        /*
        this.runnableuser = new Runnable() {
            @Override
            public void run() {
                YFMainActivity.access$15(YFMainActivity.this, new AsyncHttpClient());
                final RequestParams requestParams = new RequestParams();
                requestParams.setUseJsonStreamer(true);
                requestParams.put("Device", YFMainActivity.this.Device);
                if (YFMainActivity.this.clientuser != null) {
                    YFMainActivity.this.clientuser.cancelAllRequests(true);
                    YFMainActivity.this.clientuser.cancelAllRequests(true);
                    YFMainActivity.this.clientuser.cancelAllRequests(true);
                }
                YFMainActivity.this.clientuser.post(YFMainActivity.this.urluser, requestParams, new AsyncHttpResponseHandler() {
                    @Override
                    public void onFailure(final int n, final Header[] array, final byte[] array2, final Throwable t) {
                        YFMainActivity.this.handleruser.postDelayed(YFMainActivity.this.runnableuser, 1000L);
                    }

                    @Override
                    public void onSuccess(final int p0, final Header[] p1, final byte[] p2) {
                        //
                        // This method could not be decompiled.
                        //
                        // Original Bytecode:
                        //
                        //     3: dup
                        //     4: aload_3
                        //     5: ldc             "utf-8"
                        //     7: invokespecial   java/lang/String.<init>:([BLjava/lang/String;)V
                        //    10: astore_2
                        //    11: ldc             "AsyncHttp\u83b7\u53d6\u7528\u6237\u4fe1\u606f\u83b7\u53d6\u7528\u6237\u4fe1\u606f11111111111"
                        //    13: new             Ljava/lang/StringBuilder;
                        //    16: dup
                        //    17: aload_2
                        //    18: invokestatic    java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
                        //    21: invokespecial   java/lang/StringBuilder.<init>:(Ljava/lang/String;)V
                        //    24: invokevirtual   java/lang/StringBuilder.toString:()Ljava/lang/String;
                        //    27: invokestatic    android/util/Log.e:(Ljava/lang/String;Ljava/lang/String;)I
                        //    30: pop
                        //    31: aload_0
                        //    32: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //    35: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //    38: new             Lorg/json/JSONObject;
                        //    41: dup
                        //    42: aload_2
                        //    43: invokespecial   org/json/JSONObject.<init>:(Ljava/lang/String;)V
                        //    46: invokestatic    com/webmm/electretdemo/YFMainActivity.access$8:(Lcom/webmm/electretdemo/YFMainActivity;Lorg/json/JSONObject;)V
                        //    49: aload_0
                        //    50: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //    53: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //    56: invokestatic    com/webmm/electretdemo/YFMainActivity.access$9:(Lcom/webmm/electretdemo/YFMainActivity;)Lorg/json/JSONObject;
                        //    59: ldc             "success"
                        //    61: invokevirtual   org/json/JSONObject.getString:(Ljava/lang/String;)Ljava/lang/String;
                        //    64: astore_3
                        //    65: aload_3
                        //    66: ldc             "false"
                        //    68: invokevirtual   java/lang/String.equals:(Ljava/lang/Object;)Z
                        //    71: ifeq            124
                        //    74: aload_0
                        //    75: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //    78: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //    81: getfield        com/webmm/electretdemo/YFMainActivity.handleruser:Landroid/os/Handler;
                        //    84: aload_0
                        //    85: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //    88: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //    91: getfield        com/webmm/electretdemo/YFMainActivity.runnableuser:Ljava/lang/Runnable;
                        //    94: invokevirtual   android/os/Handler.removeCallbacks:(Ljava/lang/Runnable;)V
                        //    97: aload_0
                        //    98: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   101: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   104: getfield        com/webmm/electretdemo/YFMainActivity.handleruser:Landroid/os/Handler;
                        //   107: aload_0
                        //   108: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   111: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   114: getfield        com/webmm/electretdemo/YFMainActivity.runnableuser:Ljava/lang/Runnable;
                        //   117: ldc2_w          1000
                        //   120: invokevirtual   android/os/Handler.postDelayed:(Ljava/lang/Runnable;J)Z
                        //   123: pop
                        //   124: aload_3
                        //   125: ldc             "true"
                        //   127: invokevirtual   java/lang/String.equals:(Ljava/lang/Object;)Z
                        //   130: ifeq            750
                        //   133: ldc             "DSDADSADSADAD"
                        //   135: new             Ljava/lang/StringBuilder;
                        //   138: dup
                        //   139: aload_2
                        //   140: invokestatic    java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
                        //   143: invokespecial   java/lang/StringBuilder.<init>:(Ljava/lang/String;)V
                        //   146: invokevirtual   java/lang/StringBuilder.toString:()Ljava/lang/String;
                        //   149: invokestatic    android/util/Log.e:(Ljava/lang/String;Ljava/lang/String;)I
                        //   152: pop
                        //   153: aload_0
                        //   154: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   157: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   160: invokestatic    com/webmm/electretdemo/YFMainActivity.access$9:(Lcom/webmm/electretdemo/YFMainActivity;)Lorg/json/JSONObject;
                        //   163: ldc             "sex"
                        //   165: invokevirtual   org/json/JSONObject.getString:(Ljava/lang/String;)Ljava/lang/String;
                        //   168: astore_2
                        //   169: aload_0
                        //   170: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   173: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   176: invokestatic    com/webmm/electretdemo/YFMainActivity.access$9:(Lcom/webmm/electretdemo/YFMainActivity;)Lorg/json/JSONObject;
                        //   179: ldc             "age"
                        //   181: invokevirtual   org/json/JSONObject.getString:(Ljava/lang/String;)Ljava/lang/String;
                        //   184: pop
                        //   185: aload_0
                        //   186: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   189: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   192: invokestatic    com/webmm/electretdemo/YFMainActivity.access$9:(Lcom/webmm/electretdemo/YFMainActivity;)Lorg/json/JSONObject;
                        //   195: ldc             "height"
                        //   197: invokevirtual   org/json/JSONObject.getString:(Ljava/lang/String;)Ljava/lang/String;
                        //   200: astore_3
                        //   201: aload_0
                        //   202: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   205: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   208: invokestatic    com/webmm/electretdemo/YFMainActivity.access$9:(Lcom/webmm/electretdemo/YFMainActivity;)Lorg/json/JSONObject;
                        //   211: ldc             "weight"
                        //   213: invokevirtual   org/json/JSONObject.getString:(Ljava/lang/String;)Ljava/lang/String;
                        //   216: astore          4
                        //   218: aload_0
                        //   219: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   222: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   225: invokestatic    com/webmm/electretdemo/YFMainActivity.access$9:(Lcom/webmm/electretdemo/YFMainActivity;)Lorg/json/JSONObject;
                        //   228: ldc             "name"
                        //   230: invokevirtual   org/json/JSONObject.getString:(Ljava/lang/String;)Ljava/lang/String;
                        //   233: pop
                        //   234: aload_0
                        //   235: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   238: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   241: invokestatic    com/webmm/electretdemo/YFMainActivity.access$11:(Lcom/webmm/electretdemo/YFMainActivity;)Landroid/webkit/WebView;
                        //   244: bipush          8
                        //   246: invokevirtual   android/webkit/WebView.setVisibility:(I)V
                        //   249: aload_0
                        //   250: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   253: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   256: getfield        com/webmm/electretdemo/YFMainActivity.handleruser:Landroid/os/Handler;
                        //   259: aload_0
                        //   260: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   263: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   266: getfield        com/webmm/electretdemo/YFMainActivity.runnableuser:Ljava/lang/Runnable;
                        //   269: invokevirtual   android/os/Handler.removeCallbacks:(Ljava/lang/Runnable;)V
                        //   272: aload_0
                        //   273: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   276: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   279: aload_3
                        //   280: invokestatic    com/webmm/electretdemo/YFMainActivity.access$17:(Lcom/webmm/electretdemo/YFMainActivity;Ljava/lang/String;)V
                        //   283: aload_0
                        //   284: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   287: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   290: aload           4
                        //   292: invokestatic    com/webmm/electretdemo/YFMainActivity.access$18:(Lcom/webmm/electretdemo/YFMainActivity;Ljava/lang/String;)V
                        //   295: aload_2
                        //   296: ldc             "1"
                        //   298: invokevirtual   java/lang/String.equals:(Ljava/lang/Object;)Z
                        //   301: ifeq            715
                        //   304: aload_0
                        //   305: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   308: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   311: bipush          36
                        //   313: invokestatic    com/webmm/electretdemo/YFMainActivity.access$19:(Lcom/webmm/electretdemo/YFMainActivity;I)V
                        //   316: aload_0
                        //   317: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   320: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   323: ldc             "1990-07-10"
                        //   325: ldc             "-"
                        //   327: invokevirtual   java/lang/String.split:(Ljava/lang/String;)[Ljava/lang/String;
                        //   330: iconst_0
                        //   331: aaload
                        //   332: invokestatic    com/webmm/electretdemo/YFMainActivity.access$20:(Lcom/webmm/electretdemo/YFMainActivity;Ljava/lang/String;)V
                        //   335: aload_0
                        //   336: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   339: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   342: ldc             "1990-07-10"
                        //   344: ldc             "-"
                        //   346: invokevirtual   java/lang/String.split:(Ljava/lang/String;)[Ljava/lang/String;
                        //   349: iconst_1
                        //   350: aaload
                        //   351: invokestatic    com/webmm/electretdemo/YFMainActivity.access$21:(Lcom/webmm/electretdemo/YFMainActivity;Ljava/lang/String;)V
                        //   354: new             Ljava/lang/StringBuilder;
                        //   357: dup
                        //   358: aload_0
                        //   359: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   362: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   365: invokestatic    com/webmm/electretdemo/YFMainActivity.access$22:(Lcom/webmm/electretdemo/YFMainActivity;)Ljava/lang/String;
                        //   368: invokestatic    java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
                        //   371: invokespecial   java/lang/StringBuilder.<init>:(Ljava/lang/String;)V
                        //   374: ldc             "-"
                        //   376: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   379: aload_0
                        //   380: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   383: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   386: invokestatic    com/webmm/electretdemo/YFMainActivity.access$23:(Lcom/webmm/electretdemo/YFMainActivity;)Ljava/lang/String;
                        //   389: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   392: ldc             "-"
                        //   394: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   397: ldc             "1990-07-10"
                        //   399: ldc             "-"
                        //   401: invokevirtual   java/lang/String.split:(Ljava/lang/String;)[Ljava/lang/String;
                        //   404: iconst_2
                        //   405: aaload
                        //   406: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   409: invokevirtual   java/lang/StringBuilder.toString:()Ljava/lang/String;
                        //   412: astore_2
                        //   413: new             Ljava/text/SimpleDateFormat;
                        //   416: dup
                        //   417: ldc             "yyyy-MM-dd"
                        //   419: invokespecial   java/text/SimpleDateFormat.<init>:(Ljava/lang/String;)V
                        //   422: astore_3
                        //   423: aload_3
                        //   424: aload_2
                        //   425: invokevirtual   java/text/SimpleDateFormat.parse:(Ljava/lang/String;)Ljava/util/Date;
                        //   428: astore_2
                        //   429: aload_0
                        //   430: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   433: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   436: aload_2
                        //   437: invokevirtual   java/util/Date.getTime:()J
                        //   440: ldc2_w          1000
                        //   443: ldiv
                        //   444: ldc2_w          28800
                        //   447: ladd
                        //   448: ldc2_w          24
                        //   451: ldiv
                        //   452: ldc2_w          3600
                        //   455: ldiv
                        //   456: ldc2_w          25569
                        //   459: ladd
                        //   460: l2d
                        //   461: invokestatic    com/webmm/electretdemo/YFMainActivity.access$24:(Lcom/webmm/electretdemo/YFMainActivity;D)V
                        //   464: new             Ljava/lang/StringBuilder;
                        //   467: dup
                        //   468: aload_0
                        //   469: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   472: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   475: invokestatic    com/webmm/electretdemo/YFMainActivity.access$25:(Lcom/webmm/electretdemo/YFMainActivity;)Ljava/lang/String;
                        //   478: invokestatic    java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
                        //   481: invokespecial   java/lang/StringBuilder.<init>:(Ljava/lang/String;)V
                        //   484: ldc             ";"
                        //   486: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   489: aload_0
                        //   490: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   493: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   496: invokestatic    com/webmm/electretdemo/YFMainActivity.access$26:(Lcom/webmm/electretdemo/YFMainActivity;)Ljava/lang/String;
                        //   499: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   502: ldc             ";"
                        //   504: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   507: aload_0
                        //   508: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   511: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   514: invokestatic    com/webmm/electretdemo/YFMainActivity.access$27:(Lcom/webmm/electretdemo/YFMainActivity;)D
                        //   517: invokevirtual   java/lang/StringBuilder.append:(D)Ljava/lang/StringBuilder;
                        //   520: ldc             ";"
                        //   522: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   525: aload_0
                        //   526: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   529: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   532: invokestatic    com/webmm/electretdemo/YFMainActivity.access$22:(Lcom/webmm/electretdemo/YFMainActivity;)Ljava/lang/String;
                        //   535: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   538: ldc             ";"
                        //   540: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   543: aload_0
                        //   544: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   547: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   550: invokestatic    com/webmm/electretdemo/YFMainActivity.access$23:(Lcom/webmm/electretdemo/YFMainActivity;)Ljava/lang/String;
                        //   553: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   556: ldc             ";"
                        //   558: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   561: aload_0
                        //   562: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   565: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   568: invokestatic    com/webmm/electretdemo/YFMainActivity.access$6:(Lcom/webmm/electretdemo/YFMainActivity;)Ljava/lang/String;
                        //   571: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   574: invokevirtual   java/lang/StringBuilder.toString:()Ljava/lang/String;
                        //   577: putstatic       com/serenegiant/vo/utils/Catch.xinxi:Ljava/lang/String;
                        //   580: new             Ljava/io/File;
                        //   583: dup
                        //   584: new             Ljava/lang/StringBuilder;
                        //   587: dup
                        //   588: invokestatic    android/os/Environment.getExternalStorageDirectory:()Ljava/io/File;
                        //   591: invokevirtual   java/io/File.getPath:()Ljava/lang/String;
                        //   594: invokestatic    java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
                        //   597: invokespecial   java/lang/StringBuilder.<init>:(Ljava/lang/String;)V
                        //   600: ldc             "/ResultData/"
                        //   602: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
                        //   605: invokevirtual   java/lang/StringBuilder.toString:()Ljava/lang/String;
                        //   608: invokespecial   java/io/File.<init>:(Ljava/lang/String;)V
                        //   611: astore_2
                        //   612: aload_0
                        //   613: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   616: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   619: aload_2
                        //   620: invokestatic    com/webmm/electretdemo/YFMainActivity.access$28:(Lcom/webmm/electretdemo/YFMainActivity;Ljava/io/File;)V
                        //   623: new             Landroid/content/Intent;
                        //   626: dup
                        //   627: aload_0
                        //   628: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   631: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   634: ldc             Lcom/webmm/electretdemo/YFResultActivity;.class
                        //   636: invokespecial   android/content/Intent.<init>:(Landroid/content/Context;Ljava/lang/Class;)V
                        //   639: astore_2
                        //   640: aload_0
                        //   641: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   644: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   647: aload_2
                        //   648: invokevirtual   com/webmm/electretdemo/YFMainActivity.startActivity:(Landroid/content/Intent;)V
                        //   651: aload_0
                        //   652: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   655: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   658: invokestatic    com/webmm/electretdemo/YFMainActivity.access$29:(Lcom/webmm/electretdemo/YFMainActivity;)Landroid/hardware/Camera;
                        //   661: ifnull          704
                        //   664: aload_0
                        //   665: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   668: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   671: invokestatic    com/webmm/electretdemo/YFMainActivity.access$29:(Lcom/webmm/electretdemo/YFMainActivity;)Landroid/hardware/Camera;
                        //   674: aconst_null
                        //   675: invokevirtual   android/hardware/Camera.setPreviewCallback:(Landroid/hardware/Camera.PreviewCallback;)V
                        //   678: aload_0
                        //   679: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   682: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   685: invokestatic    com/webmm/electretdemo/YFMainActivity.access$29:(Lcom/webmm/electretdemo/YFMainActivity;)Landroid/hardware/Camera;
                        //   688: invokevirtual   android/hardware/Camera.stopPreview:()V
                        //   691: aload_0
                        //   692: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   695: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   698: invokestatic    com/webmm/electretdemo/YFMainActivity.access$29:(Lcom/webmm/electretdemo/YFMainActivity;)Landroid/hardware/Camera;
                        //   701: invokevirtual   android/hardware/Camera.release:()V
                        //   704: aload_0
                        //   705: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   708: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   711: invokevirtual   com/webmm/electretdemo/YFMainActivity.finish:()V
                        //   714: return
                        //   715: aload_0
                        //   716: getfield        com/webmm/electretdemo/YFMainActivity$6$1.this$1:Lcom/webmm/electretdemo/YFMainActivity$6;
                        //   719: invokestatic    com/webmm/electretdemo/YFMainActivity$6.access$0:(Lcom/webmm/electretdemo/YFMainActivity$6;)Lcom/webmm/electretdemo/YFMainActivity;
                        //   722: bipush          37
                        //   724: invokestatic    com/webmm/electretdemo/YFMainActivity.access$19:(Lcom/webmm/electretdemo/YFMainActivity;I)V
                        //   727: goto            316
                        //   730: astore_2
                        //   731: aload_2
                        //   732: invokevirtual   org/json/JSONException.printStackTrace:()V
                        //   735: return
                        //   736: astore_2
                        //   737: aload_2
                        //   738: invokevirtual   java/io/UnsupportedEncodingException.printStackTrace:()V
                        //   741: return
                        //   742: astore_2
                        //   743: aload_2
                        //   744: invokevirtual   java/text/ParseException.printStackTrace:()V
                        //   747: goto            464
                        //   750: return
                        //    Exceptions:
                        //  Try           Handler
                        //  Start  End    Start  End    Type
                        //  -----  -----  -----  -----  --------------------------------------
                        //  0      31     736    742    Ljava/io/UnsupportedEncodingException;
                        //  31     124    730    736    Lorg/json/JSONException;
                        //  31     124    736    742    Ljava/io/UnsupportedEncodingException;
                        //  124    316    730    736    Lorg/json/JSONException;
                        //  124    316    736    742    Ljava/io/UnsupportedEncodingException;
                        //  316    423    730    736    Lorg/json/JSONException;
                        //  316    423    736    742    Ljava/io/UnsupportedEncodingException;
                        //  423    464    742    750    Ljava/text/ParseException;
                        //  423    464    730    736    Lorg/json/JSONException;
                        //  423    464    736    742    Ljava/io/UnsupportedEncodingException;
                        //  464    704    730    736    Lorg/json/JSONException;
                        //  464    704    736    742    Ljava/io/UnsupportedEncodingException;
                        //  704    714    730    736    Lorg/json/JSONException;
                        //  704    714    736    742    Ljava/io/UnsupportedEncodingException;
                        //  715    727    730    736    Lorg/json/JSONException;
                        //  715    727    736    742    Ljava/io/UnsupportedEncodingException;
                        //  731    735    736    742    Ljava/io/UnsupportedEncodingException;
                        //  743    747    730    736    Lorg/json/JSONException;
                        //  743    747    736    742    Ljava/io/UnsupportedEncodingException;
                        //
                        // The error that occurred was:
                        //
                        // java.lang.IllegalStateException: Expression is linked from several locations: Label_0464:
                        //     at com.strobel.decompiler.ast.Error.expressionLinkedFromMultipleLocations(Error.java:27)
                        //     at com.strobel.decompiler.ast.AstOptimizer.mergeDisparateObjectInitializations(AstOptimizer.java:2596)
                        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:235)
                        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:42)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:214)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:99)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:757)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethod(AstBuilder.java:655)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:532)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:499)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:141)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:130)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformCall(AstMethodBodyBuilder.java:1163)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformByteCode(AstMethodBodyBuilder.java:1010)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformExpression(AstMethodBodyBuilder.java:540)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformByteCode(AstMethodBodyBuilder.java:554)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformExpression(AstMethodBodyBuilder.java:540)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformNode(AstMethodBodyBuilder.java:392)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformBlock(AstMethodBodyBuilder.java:333)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:294)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:99)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:757)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethod(AstBuilder.java:655)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:532)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:499)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:141)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:130)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformCall(AstMethodBodyBuilder.java:1163)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformByteCode(AstMethodBodyBuilder.java:1010)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformExpression(AstMethodBodyBuilder.java:540)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformByteCode(AstMethodBodyBuilder.java:554)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformExpression(AstMethodBodyBuilder.java:540)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformNode(AstMethodBodyBuilder.java:392)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.transformBlock(AstMethodBodyBuilder.java:333)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:294)
                        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:99)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:757)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createConstructor(AstBuilder.java:692)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:529)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:499)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:141)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:130)
                        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addType(AstBuilder.java:105)
                        //     at com.strobel.decompiler.languages.java.JavaLanguage.buildAst(JavaLanguage.java:71)
                        //     at com.strobel.decompiler.languages.java.JavaLanguage.decompileType(JavaLanguage.java:59)
                        //     at us.deathmarine.luyten.DecompilerLinkProvider.generateContent(DecompilerLinkProvider.java:97)
                        //     at us.deathmarine.luyten.OpenFile.decompileWithNavigationLinks(OpenFile.java:469)
                        //     at us.deathmarine.luyten.OpenFile.decompile(OpenFile.java:442)
                        //     at us.deathmarine.luyten.Model.extractClassToTextPane(Model.java:420)
                        //     at us.deathmarine.luyten.Model.openEntryByTreePath(Model.java:339)
                        //     at us.deathmarine.luyten.Model$TreeListener$1.run(Model.java:266)
                        //
                        throw new IllegalStateException("An error occurred while decompiling this method.");
                    }
                });
            }
        };
        */
//        this.urlfinal = "http://www.zyfrontendserver.healthpool1276.com/health/pad3.0/pc.receivepass.php";
        this.random = "";

        /**
         * @Description
         * @Author AntLiu
         * @Update 2018/10/28 22:11
         */
        this.networkTaskStartGou = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"networkTaskStartGou.start");
                SyncHttpClient client = new SyncHttpClient();
                client.get(YFMainActivity.URL_START, new TextHttpResponseHandler() {
                    @Override
                    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable ex) {
//                        YFMainActivity.this.response = "";
                        YFMainActivity.this.handlerfailGou.post(YFMainActivity.this.runnablefailGou);
                        Log.w("[E]"+"http",responseString);
                        ex.printStackTrace();
                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, String responseString) {
                        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/,"responseString="+ responseString);
//                        Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "YFMainActivity.this.response="+responseString);
                        if(responseString!=null && responseString.length()>=8){
                            YFMainActivity.this.random = responseString.substring(0, 8);
                            YFMainActivity.this.handlersuanfaload.post(YFMainActivity.this.runnablesuanfaload);
                        }else{
                            //TODO CHECK Guess : Add else-block with runnablefailGou
                            YFMainActivity.this.handlerfailGou.post(YFMainActivity.this.runnablefailGou);
                        }
                    }
                });
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"networkTaskStartGou.end");
            }
        };

        this.handlerfailGou = new Handler();
        this.runnablefailGou = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablefailGou.start");
                if (YFMainActivity.this.random.equals("")) {
                    YFMainActivity.this.ShowMessage("联网失败");
                }
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablefailGou.end");
            }
        };
        this.handlerclose = new Handler();
        this.runnableclose = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnableclose.start");
                YFMainActivity.this.finish();
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnableclose.end");
            }
        };

        this.networkTaskGou = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"networkTaskGou.start");
                final DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
                try {
                    final HttpPost httpPost = new HttpPost(YFMainActivity.this.URL_FINAL);
                    final BasicHttpParams params = new BasicHttpParams();
                    final Gson gson = new Gson();
                    final HashMap<String, String> hashMap = new HashMap<String, String>();
                    hashMap.put("rand", YFMainActivity.this.random);
                    hashMap.put("encode", YFMainActivity.this.goushu);
                    hashMap.put("ID", YFMainActivity.this.houbawei);
                    final String json = gson.toJson(hashMap);
                    final StringEntity entity = new StringEntity(json, "utf-8");
                    entity.setContentType("application/json");
                    entity.setContentEncoding("utf-8");
                    httpPost.setEntity((HttpEntity) entity);
                    httpPost.setParams((HttpParams) params);
                    Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "发送的数据:" + json.toString());
                    final HttpResponse execute = ((HttpClient) defaultHttpClient).execute((HttpUriRequest) httpPost);
                    final StatusLine statusLine = execute.getStatusLine();
                    if (statusLine != null && statusLine.getStatusCode() == 200) {
                        final HttpEntity entity2 = execute.getEntity();
                        if (entity != null) {
                            YFMainActivity.this.jsonObject2 = new JSONObject(readInputStream(entity2.getContent()));
                            Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "YFMainActivity.this.jsonObject2="+YFMainActivity.this.jsonObject2.toString());
                            Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "Catch.fristencode="+Catch.fristencode);
                            if (Catch.fristencode) {
                                Catch.fristencode = false;
                                YFMainActivity.this.showTwoTim = YFMainActivity.this.jsonObject2.getString("showTwoTim");
                                YFMainActivity.this.handlerxianshi.post(YFMainActivity.this.runnablexianshi);
                            }
                            if (YFMainActivity.this.jsonObject2.getString("success").equals("true")) {
                                Catch.Gou = true;
                                Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "networkTaskGou.:true!");
                            }
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    throw new RuntimeException(ex);
                }
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"networkTaskGou.end");
            }
        };
        this.handlerxianshi = new Handler();
        this.runnablexianshi = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablexianshi.start");
//                Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnablexianshi Start."+new Date().toString());
//                Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "YFMainActivity.this.showTwoTim="+YFMainActivity.this.showTwoTim);
                if (YFMainActivity.this.showTwoTim.equals("true")) {
//                    YFMainActivity.this.devicetext.setText(YFMainActivity.this.deviceId);
                    YFMainActivity.this.devicetext.setText(YFMainActivity.this.deviceId2);
                    YFMainActivity.this.devicetext.setBackgroundResource(R.mipmap.tuanyuan);
//                    Bitmap image = QRCodeUtil.createQRCodeBitmap(YFMainActivity.this.deviceId, 100, 100);
                    Bitmap image = QRCodeUtil.createQRCodeBitmap(YFMainActivity.this.deviceId2, 100, 100);
                    Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "image is null?"+(image==null));
                    YFMainActivity.this.deviceimg.setImageBitmap(image);
//                    return;
                }else{
                    YFMainActivity.this.devicetext.setBackground((Drawable) null);
                    YFMainActivity.this.devicetext.setVisibility(View.GONE);
                    YFMainActivity.this.deviceimg.setVisibility(View.GONE);
                }
//                Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "###runnablexianshi End."+new Date().toString());
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablexianshi.end");
            }
        };
        this.handlersuanfaload = new Handler();
        this.runnablesuanfaload = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablesuanfaload.start");
                YFMainActivity.this.f_EncString();
                YFMainActivity.this.f_YReadString();
                YFMainActivity.this.handlerfinalGou1.postDelayed(YFMainActivity.this.runnablefinalGou1, 200L);
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablesuanfaload.end");
            }
        };
        this.handlerstartGou1 = new Handler();
        this.runnablestartGou1 = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablestartGou1.start");
                new Thread(YFMainActivity.this.networkTaskStartGou).start();
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablestartGou1.end");
            }
        };
        this.handlerfinalGou1 = new Handler();
        this.runnablefinalGou1 = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablefinalGou1.start");
                new Thread(YFMainActivity.this.networkTaskGou).start();
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablefinalGou1.end");
            }
        };
        this.handlerstartGou = new Handler();
        this.runnablestartGou = new Runnable() {
            @Override
            public void run() {
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablestartGou.start");
                YFMainActivity.this.f_getid();
//                Log.e(YFMainActivity.this.getClass().getSimpleName(), "Runnables:"+"runnablestartGou.end");
            }
        };
    }


    protected void onCreate(final Bundle bundle) {
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onCreate().start");
//        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/,"=====================================================>onCreate()");
        Catch.logValues();
        if (DEVELOPER_MODE) {
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                    .detectDiskReads()
                    .detectDiskWrites()
                    .detectNetwork()   // or .detectAll() for all detectable problems
                    .penaltyLog()
                    .build());
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects()
                    .detectLeakedClosableObjects()
                    .penaltyLog()
                    .penaltyDeath()
                    .build());
        }
        super.onCreate(bundle);

        this.requestWindowFeature(1);
//        this.setContentView(MResource.getIdByName((Context) this.getApplication(), "layout", "yfmain"));
        this.setContentView(R.layout.yfmain);
//        this.version = true;
        Catch.reset = true;
        Catch.camera2start = false;
        Catch.frame = 0;
        Catch.celiang = false;
        Catch.start = false;
        Catch.weight = "";
        Catch.heigh = 0;
        Catch.left = 0;
        Catch.top = 0;
        Catch.point = new ArrayList<String>();
        Catch.times = true;
        Catch.count = 0;
        Catch.showencode = false;
        Catch.weizhi = new int[]{1000, 1001, 1002, 1003, 1004, 1005};
        Catch.encodeerro = false;
        Catch.version = "";
        Catch.tuisong = false;
        Catch.tuisongerro = false;
        Catch.wenbenxianshi = false;
        Catch.weigherro = false;
        Catch.weightuisong = false;
        Catch.lastweigh = "";

        this.wifi_iconImg = (ImageView)this.findViewById(MResource.getIdByName((Context) this.getApplication(), "id","wifi_iconImg"));
        this.wifi_iconImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(YFMainActivity.this, WifiSelecterActivity.class));
            }
        });
        this.dianchiTv = this.findViewById(MResource.getIdByName((Context) this.getApplication(),"id","dianchiTv"));
        //电池电量部分
        dianchi();

//        this.imgview = (ImageView) this.findViewById(MResource.getIdByName((Context) this.getApplication(), "id", "imgview"));
        this.imgview = this.findViewById(R.id.imgview);
//        this.noticeTextView1 = (TextView) this.findViewById(MResource.getIdByName((Context) this.getApplication(), "id", "tishi"));
        this.noticeTextView1 = this.findViewById(R.id.tishi);
//        this.noticeTextView2 = (TextView) this.findViewById(MResource.getIdByName((Context) this.getApplication(), "id", "tishi1"));
        this.noticeTextView2 = this.findViewById(R.id.tishi1);
//        this.daojishi = (TextView) this.findViewById(MResource.getIdByName((Context) this.getApplication(), "id", "daojishi"));
        this.daojishi = this.findViewById(R.id.daojishi);
//        this.deviceimg = (ImageView) this.findViewById(MResource.getIdByName((Context) this.getApplication(), "id", "deviceencode"));
        this.deviceimg = this.findViewById(R.id.deviceencode);
//        (this.devicetext = (TextView) this.findViewById(MResource.getIdByName((Context) this.getApplication(), "id", "device"))).setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/Longview.ttf"));
        this.devicetext = this.findViewById(R.id.device);
        this.devicetext.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/Longview.ttf"));
        this.noticeTextView1.setText("脸部对准摄像头");
        this.noticeTextView2.setText("生成您的监测二维码");
//        this.surfaceview = (SurfaceView) this.findViewById(MResource.getIdByName((Context) this.getApplication(), "id", "preview_view"));
        this.surfaceview = this.findViewById(R.id.preview_view);
        (this.surfaceholder = this.surfaceview.getHolder()).setType(3);
        this.surfaceholder.addCallback((SurfaceHolder.Callback) this);
//        (this.webview = (WebView) this.findViewById(MResource.getIdByName((Context) this.getApplication(), "id", "webview2"))).setVisibility(View.GONE);
        this.webview = this.findViewById(R.id.webview2);
        this.webview.setVisibility(View.GONE);
        this.handlerstartcl.postDelayed(this.runnablestartcl, 100L);
        UsbManager mUsbManager = (UsbManager) this.getSystemService(Context.USB_SERVICE);//this.mUsbManager
        this.aSyunew699 = new ASyunew699(mUsbManager);
        this.usbEncryptionDogDevice = this.aSyunew699.FindPort(0);
        if (this.aSyunew699.get_LastError() != 0) {
            Log.i(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/,"未找到加密锁×");
            this.ShowMessage("未找到加密锁,请插入加密锁后，再进行操作。");
            this.handlerclose.postDelayed(this.runnableclose, 2000L);
        } else {
            Log.i(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/,"已找到加密锁√");
            this.handlerstartGou.post(this.runnablestartGou);
        }
        final WindowManager windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "22222"+String.valueOf(windowManager.getDefaultDisplay().getWidth()) + ";" + windowManager.getDefaultDisplay().getHeight());
        this.deleteFile1("/updateVersion/chanpin.apk");

        //加载并显示当前版本信息
        this.versionView = this.findViewById(R.id.versionView);
        int versionCode = ApkUtils.getVersionCode((Context) YFMainActivity.this);
        String versionName = ApkUtils.getVersionName(YFMainActivity.this);
        this.versionView.setText("Version:"+versionName+"("+versionCode+")");
        this.versionView.setVisibility(View.GONE);

        this.handlerversion.postDelayed(this.runnableversion, 3000L);
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onCreate().end");
    }

    @Override
    protected void onStart() {
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onStart().start");
        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/,"=====================================================>onStart()");
        super.onStart();
//        this.camera = null;
//        this.deviceId = "";
//        this.djs = 60;
//        this.random = "";

        //通知系统进入全屏模式
        Intent intent = new Intent("com.android.action.hide_navigationbar");
        sendBroadcast(intent);

//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onStart().end");
    }

    @Override
    protected void onResume() {
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onResume().start");
//        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/,"=====================================================>onResume()");
        super.onResume();
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onResume().end");
    }

    @Override
    protected void onPause() {
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onPause().start");
//        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/,"=====================================================>onPause()");
        super.onPause();
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onPause().end");
    }

    @Override
    protected void onStop() {
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onStop().start");
//        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/,"=====================================================>onStop()");
        if(YFMainActivity.this.camera!=null) {
            YFMainActivity.this.camera.setPreviewCallback(null);
            YFMainActivity.this.camera.stopPreview();
            YFMainActivity.this.camera.release();
            YFMainActivity.this.camera = null;
        }
        super.onStop();
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onStop().end");
    }

    @Override
    protected void onDestroy() {
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onDestroy().start");
//        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/,"=====================================================>onDestroy()");
//        YFMainActivity.this.camera.setPreviewCallback(null);
//        YFMainActivity.this.camera.stopPreview();
//        YFMainActivity.this.camera.release();
        super.onDestroy();
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "LifeCycles:"+"onDestroy().end");
    }

    private void ShowMessage(final String s) {
        Toast.makeText((Context) this, s, Toast.LENGTH_LONG).show();
    }

    /**
     * @Description 递归删除文件
     * @Author AntLiu
     * @Update 2018/10/24 10:49
     * @return viud->boolean
     */
    private boolean deleteAllFiles(final File file) {
        if(!file.exists()){
//            Log.i(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "file not exists:"+file.getAbsolutePath());
            return false;
        }
        if(file.isDirectory()){
            File[] files = file.listFiles();
            for (int i=0; i<files.length; i++){
                deleteAllFiles(files[i]);
            }
        }
        return file.delete();
    }

    private boolean deleteFile1(final String s) {
        final File file = new File(Environment.getExternalStorageDirectory(), s);
//        Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "path="+file.getAbsolutePath());
        if (!file.exists() || !file.isFile()) {
            System.out.println("删除单个文件失败：" + s + "不存在！");
            return false;
        }
        if (file.delete()) {
            System.out.println("删除单个文件" + s + "成功！");
            return true;
        }
        System.out.println("删除单个文件" + s + "失败！");
        return false;
    }

    public static void encodeYUV420SP(final byte[] array, final int[] array2, final int n, final int n2) throws Exception {
        int n3 = 0;
        int n4 = n * n2;
        int n5 = 0;
        int n7;
        int n8;
        int n21;
        for (int i = 0; i < n2; ++i, n21 = n7, n4 = n8, n3 = n21) {
            int j = 0;
            final int n6 = n4;
            n7 = n3;
            n8 = n6;
            while (j < n) {
                final int n9 = array2[n5];
                final int n10 = (array2[n5] & 0xFF0000) >> 16;
                final int n11 = (array2[n5] & 0xFF00) >> 8;
                final int n12 = (array2[n5] & 0xFF) >> 0;
                final int n13 = (n10 * 66 + n11 * 129 + n12 * 25 + 128 >> 8) + 16;
                final int n14 = (n10 * -38 - n11 * 74 + n12 * 112 + 128 >> 8) + 128;
                final int n15 = (n10 * 112 - n11 * 94 - n12 * 18 + 128 >> 8) + 128;
                int n16;
                if (n13 < 0) {
                    n16 = 0;
                } else if ((n16 = n13) > 255) {
                    n16 = 255;
                }
                array[n7] = (byte) n16;
                int n17 = n8;
                if (i % 2 == 0) {
                    n17 = n8;
                    if (n5 % 2 == 0) {
                        final int n18 = n8 + 1;
                        int n19;
                        if (n15 < 0) {
                            n19 = 0;
                        } else if ((n19 = n15) > 255) {
                            n19 = 255;
                        }
                        array[n8] = (byte) n19;
                        n17 = n18 + 1;
                        int n20;
                        if (n14 < 0) {
                            n20 = 0;
                        } else if ((n20 = n14) > 255) {
                            n20 = 255;
                        }
                        array[n18] = (byte) n20;
                    }
                }
                ++n5;
                ++j;
                n8 = n17;
                ++n7;
            }
        }
    }

    private void f_EncString() {
        if (this.aSyunew699.GetVersion(this.usbEncryptionDogDevice) >= 8) {
            this.goushu = this.aSyunew699.EncString(this.random, this.usbEncryptionDogDevice);
            if (this.aSyunew699.get_LastError() != 0) {
                return;
            }
        }
    }

    private void f_YReadString() {
        this.houbawei = this.aSyunew699.YReadString((short) 0, (short) 16, "dkkj110A", "dkkj110B", this.usbEncryptionDogDevice);
        if (this.aSyunew699.get_LastError() != 0) {
            return;
        }
        this.houbawei = this.houbawei.substring(8);
    }

    private void f_getid() {
//        Log.i(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "f_getid()");
//        final Activity activity = this;
        new UsbPermissionUtil(this, new UsbPermissionCallback() {
            @Override
            public void callback(Activity activity, UsbDevice usbDevice) {
                Log.i(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "f_getid");
                final int getID_1 = YFMainActivity.this.aSyunew699.GetID_1(YFMainActivity.this.usbEncryptionDogDevice);
//                Log.i(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "getID_1="+getID_1);
                if (YFMainActivity.this.aSyunew699.get_LastError() != 0) {
                    YFMainActivity.this.ShowMessage("返回ID1错误");
                    return;
                }
                final int getID_2 = YFMainActivity.this.aSyunew699.GetID_2(YFMainActivity.this.usbEncryptionDogDevice);
                if (YFMainActivity.this.aSyunew699.get_LastError() != 0) {
                    YFMainActivity.this.ShowMessage("返回ID2错误");
                    return;
                }
                YFMainActivity.this.f_getversion();
                YFMainActivity.this.deviceId = String.valueOf(Integer.toHexString(getID_1)) + Integer.toHexString(getID_2);
                YFMainActivity.this.deviceId2 = String.valueOf(Integer.toHexString(getID_1)) + Integer.toHexString(getID_2);
//                YFMainActivity.this.deviceIdEncode = String.valueOf(Integer.toHexString(getID_1)) + Integer.toHexString(getID_2);
//                YFMainActivity.this.deviceIdOld = String.valueOf(Integer.toHexString(getID_1)) + Integer.toHexString(getID_2);
                YFMainActivity.this.handlerstartGou1.post(YFMainActivity.this.runnablestartGou1);
            }
        }).tryGetUsbPermission();
    }


    private void f_getid_bak20181121() {
        Log.i(this.getClass().getName(), "f_getid()");
        new UsbPermissionUtil(this, new UsbPermissionCallback() {
            @Override
            public void callback(Activity activity, UsbDevice usbDevice) {
//                Log.i(YFMainActivity.this.getClass().getName(), "f_getid");
                final int getID_1 = YFMainActivity.this.yt_j6.GetID_1(YFMainActivity.this.usbEncryptionDogDevice);
//                Log.i(YFMainActivity.this.getClass().getName(), "getID_1="+getID_1);
                if (YFMainActivity.this.yt_j6.get_LastError() != 0) {
                    YFMainActivity.this.ShowMessage("返回ID1错误");
                    return;
                }
                final int getID_2 = YFMainActivity.this.yt_j6.GetID_2(YFMainActivity.this.usbEncryptionDogDevice);
                if (YFMainActivity.this.yt_j6.get_LastError() != 0) {
                    YFMainActivity.this.ShowMessage("返回ID2错误");
                    return;
                }
                YFMainActivity.this.f_getversion();
                YFMainActivity.this.deviceId = String.valueOf(Integer.toHexString(getID_1)) + Integer.toHexString(getID_2);
                YFMainActivity.this.deviceId2 = String.valueOf(Integer.toHexString(getID_1)) + Integer.toHexString(getID_2);
                YFMainActivity.this.handlerstartGou1.post(YFMainActivity.this.runnablestartGou1);
            }
        }).tryGetUsbPermission();
    }

//    public Runnable runnableAfterUsbPermission;

    private void f_getid1() {
        final int getID_1 = this.aSyunew699.GetID_1(this.usbEncryptionDogDevice);
        if (this.aSyunew699.get_LastError() != 0) {
            this.ShowMessage("返回ID1错误");
            return;
        }
        final int getID_2 = this.aSyunew699.GetID_2(this.usbEncryptionDogDevice);
        if (this.aSyunew699.get_LastError() != 0) {
            this.ShowMessage("返回ID2错误");
            return;
        }
        this.f_getversion();
        this.deviceId = String.valueOf(Integer.toHexString(getID_1)) + Integer.toHexString(getID_2);
        this.deviceId2 = String.valueOf(Integer.toHexString(getID_1)) + Integer.toHexString(getID_2);
//        YFMainActivity.this.deviceIdEncode = String.valueOf(Integer.toHexString(getID_1)) + Integer.toHexString(getID_2);
        this.devicetext.setText(("设备编号：" + this.deviceId));
//        Bitmap image = QRCodeUtil.createQRCodeBitmap(YFMainActivity.this.deviceId, 200, 200);
        Bitmap image = QRCodeUtil.createQRCodeBitmap(YFMainActivity.this.deviceId2, 200, 200);
        this.deviceimg.setImageBitmap(image);
    }

    private void f_getversion() {
        this.aSyunew699.GetVersion(this.usbEncryptionDogDevice);
        if (this.aSyunew699.get_LastError() != 0) {
            this.ShowMessage("返回版本号错误");
        }
    }

    public static byte[] getNV21(final int n, final int n2, final Bitmap bitmap) throws Exception {
        final int[] array = new int[n * n2];
        bitmap.getPixels(array, 0, n, 0, 0, n, n2);
        final byte[] array2 = new byte[n * n2 * 3 / 2];
        encodeYUV420SP(array2, array, n, n2);

        //TODO DEBUG. RECYCLE FLASH REMOVED.
                    /*
        if(bitmap!=null && !bitmap.isRecycled()){
            bitmap.recycle();//SEROUNDED
        }
        */
        return array2;
    }

    private Camera.Size getOptimalPreviewSize(final List<Camera.Size> list, final int n, final int n2) {
//        Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "getOptimalPreviewSize()");
        final double n3 = n / n2;
        Camera.Size cameraSize;
        if (list == null) {
            cameraSize = null;
        } else {
            Camera.Size cameraSize2 = null;
            double n4 = Double.MAX_VALUE;
            for (final Camera.Size cameraSize3 : list) {
                if (Math.abs(cameraSize3.width / cameraSize3.height - n3) <= 0.1 && Math.abs(cameraSize3.height - n2) < n4) {
                    cameraSize2 = cameraSize3;
                    n4 = Math.abs(cameraSize3.height - n2);
                }
            }
            if ((cameraSize = cameraSize2) == null) {
                double n5 = Double.MAX_VALUE;
                final Iterator<Camera.Size> iterator2 = list.iterator();
                while (true) {
                    cameraSize = cameraSize2;
                    if (!iterator2.hasNext()) {
                        break;
                    }
                    final Camera.Size cameraSize4 = iterator2.next();
                    if (Math.abs(cameraSize4.height - n2) >= n5) {
                        continue;
                    }
                    cameraSize2 = cameraSize4;
                    n5 = Math.abs(cameraSize4.height - n2);
                }
            }
        }
        return cameraSize;
    }

    private void getPreViewImage() {
//        Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "getPreViewImage()");
//        Log.v(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "camera.setPreviewCallback(new Camera.PreviewCallback())");
        this.camera.setPreviewCallback(new Camera.PreviewCallback() {
            public void onPreviewFrame(final byte[] array, final Camera camera) {
                try {
                    previewSize = camera.getParameters().getPreviewSize();
                } catch (Exception e) {

                }
                if (Catch.reset && Catch.Gou) {
                    //TODO THIS BLOCK SEEMS TO BE IN ENDLESS-CIRCLE
                    hasFace = YFMainActivity.this.process(array, previewSize.width, previewSize.height);
                    Log.w(this.getClass().getName(), "hasFace=" + hasFace);
                    if (hasFace) {
                        Catch.frame = 0;
                        Catch.reset = false;
                        Catch.camera2start = true;
                    }
//                Camera.Parameters parameters = camera.getParameters();
                        }
                    }
            });
    }


    private void initCamera() {
//        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "initCamera()");
        Camera.Parameters parameters = this.camera.getParameters();//this.parameters
        this.getOptimalPreviewSize(parameters.getSupportedPreviewSizes(), this.surfaceview.getWidth(), this.surfaceview.getHeight());
        parameters.setPreviewSize(640, 480);
        this.setDispaly(parameters, this.camera);
        this.camera.setParameters(parameters);
        this.camera.startPreview();
        this.getPreViewImage();
    }

    public static boolean isSdCardExist() {
        return Environment.getExternalStorageState().equals("mounted");
    }

    private static String readInputStream(final InputStream inputStream) throws IOException {
        try {
            ActivityCompat.requestPermissions((Activity) App.context, PERMISSIONS_STORAGE,REQUEST_EXTERNAL_STORAGE);
            if (inputStream == null) {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 没有写的权限，去申请写的权限，会弹出对话框

        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final byte[] array = new byte[1024];
        while (true) {
            final int read = inputStream.read(array);
            if (read == -1) {
                break;
            }
            byteArrayOutputStream.write(array, 0, read);
        }
        inputStream.close();
        return URLDecoder.decode(new String(byteArrayOutputStream.toByteArray()), "utf-8");
    }


    public static void readfileriqi(final String s, final String s2) {
        if (!isSdCardExist()) {
            return;
        }
        try {
            final File file = new File(String.valueOf(Environment.getExternalStorageDirectory().getPath()) + "/ResultData");
            if (!file.exists()) {
                file.mkdirs();
            }
            final BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(new File(Environment.getExternalStorageDirectory().getPath(), "/ResultData/" + s2 + ".txt"), true));
            bufferedWriter.write("\r\n");
            bufferedWriter.write(s);
            bufferedWriter.flush();
            System.out.println("写入成功");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void setDispaly(final Camera.Parameters cameraParameters, final Camera camera) {
        if (Integer.parseInt(Build.VERSION.SDK) >= 8) {
            this.setDisplayOrientation(camera, 180);
            return;
        }
        cameraParameters.setRotation(180);
    }

    private void setDisplayOrientation(final Camera camera, final int n) {
        try {
            final Method method = camera.getClass().getMethod("setDisplayOrientation", Integer.TYPE);
            if (method != null) {
                method.invoke(camera, n);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            Log.w("[E]"+"Came_e", "图像出错");
        }
    }

    public void downLoadFile() {
        this.httpUtils = new HttpUtils();
        this.updateFile = new File(SDCardUtils.getRootDirectory() + "/updateVersion/chanpin.apk");//this.updateFile
        //通过在代码中写入linux指令修改此apk文件的权限，改为全局可读可写可执行：
        try {
            Runtime.getRuntime().exec("chmod 777 " + updateFile.getCanonicalPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
//        (this.builder2 = new UpdateingDialog.Builder((Context) this)).setCancelable(false);
//        (this.dialog1 = this.builder2.create()).show();
//        (this.updatingDialogBuilder = new UpdateingDialog.Builder((Context) this)).setCancelable(false);
//        (this.updatingDialog = this.updatingDialogBuilder.create()).show();
        httpUtils.download(ServerReqAddress.URL_UPDATE_MAX_VERSION_FILE, YFMainActivity.this.updateFile.getAbsolutePath(), true, false, new RequestCallBack<File>() {
//            private final /* synthetic */ TextView updateTextView = (TextView) YFMainActivity.this.updatingDialog.findViewById(R.id.updateTextView);
            @Override
            public void onFailure(final HttpException ex, final String s) {
                ex.printStackTrace();
//                this.updateTextView.setText("网络连接错误");
                Toast.makeText(YFMainActivity.this, "网络连接错误，无法自动更新", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onLoading(long n, final long n2, final boolean b) {
                long percent;
                if(n==0){
                    percent = 0;
                }else{
                    percent = 100L * n2 / n;
                }
                Log.w("[E]"+"1111111111", percent+"%");
                Toast.makeText(YFMainActivity.this, "已下载" + n + "%", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onStart() {

            }

            @Override
            public void onSuccess(final ResponseInfo<File> responseInfo) {
//                this.updateTextView.setText("下载完成");
//                Toast.makeText(YFMainActivity.this, "下载完成", Toast.LENGTH_SHORT).show();
//                ApkUtils.openFile(updateFile,YFMainActivity.this);
//                YFMainActivity.this.startActivity(ApkUtils.getInstallIntent(YFMainActivity.this.updateFile));
                if (Build.VERSION.SDK_INT < 23) {
                    YFMainActivity.this.startActivity(ApkUtils.getInstallIntent(YFMainActivity.this.updateFile));
                } else {
                    if (updateFile.exists()) {
                        ApkUtils.openFile(updateFile, YFMainActivity.this);
                    }
                }
            }}
                    );
    };





//    @Override
//    protected void onDestroy() {
//        YFMainActivity.this.camera.setPreviewCallback(null);
//        YFMainActivity.this.camera.stopPreview();
//        YFMainActivity.this.camera.release();
//        super.onDestroy();
//    }

    /**
     * 使用虹软识别是否有人脸
     * @Description  Try Again from re
     * @Author AntLiu
     * @Update 2018/10/30 3:11
     */
    public boolean process(byte[] var1, int var2, int var3) {
//        Log.w("[E]"+YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "process()");
        boolean var4 = false;
        ArrayList list = new ArrayList();
        AFD_FSDKError error1 = afdFsdkEngine.AFD_FSDK_InitialFaceEngine("45HHck3KNHgtRtD39QBGyNGLkJc3wGpyB6QYqcAgrMqv", "FZ46H9wgrUTo95xbXfsdxYCUGiRgQUsJ3CVDuqZ1a8gQ", 5, 16, 5);
        Log.d("com.arcsoft", "AFD_FSDK_InitialFaceEngine = " + error1.getCode());
        AFD_FSDKError error2 = afdFsdkEngine.AFD_FSDK_StillImageFaceDetection(var1, var2, var3, 2050, list);
        Log.d("com.arcsoft", "AFD_FSDK_StillImageFaceDetection =" + error2.getCode());
        Log.d("com.arcsoft", "Face=" + list.size());
        Catch.facewidth = var2;
        Catch.faceheigh = var3;
        if(list.size() > 0) {
            AFD_FSDKFace var10;
            for(Iterator var9 = list.iterator(); var9.hasNext(); Catch.facerect = var10.getRect()) {
                var10 = (AFD_FSDKFace)var9.next();
                Log.d("com.arcsoft1111", "Face:" + var10.getDegree() + ";" + var10.getRect());
            }
            var4 = true;
        } else {
            Catch.facerect = null;
        }

        error2 = afdFsdkEngine.AFD_FSDK_UninitialFaceEngine();
        Log.d("com.arcsoft", "AFD_FSDK_UninitialFaceEngine =" + error2.getCode());
        Log.d("com.arcsoft", "process.reutrn =" + var4);
        return var4;
    }

    private void dianchi() {
        //注册广播接受者java代码(电池部分)
        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        //创建广播接受者对象
        BatteryReceiver batteryReceiver = new BatteryReceiver();
        //注册receiver
        registerReceiver(batteryReceiver, intentFilter);
    }

    /**
     * 广播接受者(电池电量部分)
     */
    class BatteryReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            //判断它是否是为电量变化的Broadcast Action
            if(Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())){
                //获取当前电量
                int level = intent.getIntExtra("level", 0);
                //电量的总刻度
                int scale = intent.getIntExtra("scale", 100);
                //把它转成百分比
                dianchiTv.setText(((level*100)/scale)+"%");
            }
        }
    }

    public Bitmap rotateMyBitmap(final Bitmap bitmap) {
        final Matrix matrix = new Matrix();
        matrix.postRotate(270.0f);
        Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }

    public void surfaceChanged(final SurfaceHolder surfaceHolder, final int n, final int n2, final int n3) {
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "Functions:"+"surfaceChanged().start");
//        Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "surfaceChanged()");
        this.camera.autoFocus(new Camera.AutoFocusCallback() {
            public void onAutoFocus(final boolean b, final Camera camera) {
//                if (b) {
//                    YFMainActivity.this.initCamera();
//                }
            }
        });
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "Functions:"+"surfaceChanged().end");
    }

    @SuppressLint({"NewApi"})
    public void surfaceCreated(final SurfaceHolder previewDisplay) {
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "Functions:"+"surfaceCreated().start");
//        Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "surfaceCreated()");
        this.camera = Camera.open(0);
        try {
            this.camera.setPreviewDisplay(previewDisplay);
            final Camera.Parameters parameters = this.camera.getParameters();
            if (this.getResources().getConfiguration().orientation != 2) {
                parameters.set("orientation", "portrait");
                this.camera.setDisplayOrientation(90);
                parameters.setRotation(90);
            } else {
                parameters.set("orientation", "landscape");
                this.camera.setDisplayOrientation(0);
                parameters.setRotation(0);
            }
            this.camera.setParameters(parameters);
            this.camera.startPreview();
            this.initCamera();
            System.out.println("camera.startpreview");
        } catch (IOException ex) {
            ex.printStackTrace();
            this.camera.release();
            System.out.println("camera.release");
        }
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "Functions:"+"surfaceCreated().end");
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "Functions:"+"surfaceDestroyed().start");
//        Log.w(YFMainActivity.this.toString()/*.getClass().getSimpleName()*/, "surfaceDestroyed()");
        holder.removeCallback(this);
        if(this.camera != null) {
//            this.camera.setPreviewCallback(null);
//            this.camera.stopPreview();
//            this.camera.lock();
            this.camera.release();
            this.camera = null;
        }
//        Log.e(YFMainActivity.this.getClass().getSimpleName(), "Functions:"+"surfaceDestroyed().end");
    }

    }
